package com.hison.tandainbao.controller;

import com.hison.tandainbao.entiy.pojo.dto.BlogProperties;
import com.hison.tandainbao.response.ResponseResult;
import com.hison.tandainbao.util.AliyunUtil;
import com.hison.tandainbao.util.PlatformEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName: PictureController
 * @Descripiton: 图片控制类
 * @Author: 小郑
 * @Date： 2024/3/21 20:54
 * @Version：1.8
 **/
@Slf4j
@RestController
@RequestMapping("/upload")
@Api(value = "图片信息管理接口", tags = "图片信息管理接口")
public class PictureController {
//    @PostMapping("/blog")
//    @ApiOperation(value = "图片上传接口", produces = "application/json", httpMethod = "POST")
//    public ResponseResult  uploadImage(@RequestParam("files") MultipartFile[] multipartFiles){
//        // 处理上传的文件
//        for (MultipartFile file : multipartFiles) {
//            // 保存文件到服务器或其他地方
//            //TODO
//
//        }
//
//        //将上传的图片地址返回给前端
//
//        return null;
//    }

    @Autowired
    private BlogProperties blogProperties;

    @ApiOperation("上传文件到OSS")
    @PostMapping("/upload")
    public  ResponseResult upload(@RequestParam("file") MultipartFile file) {
        return AliyunUtil.uploadFileToOss(PlatformEnum.ARTICLE, file, blogProperties.getAliyun());
    }

    @ApiOperation("删除OOS服务器的文件")
    @ApiImplicitParam(name="fileUrl", value="要删除的文件URL", required=true)
    @DeleteMapping("/delete")
    public ResponseResult delete(@RequestParam(value = "fileUrl", required = false) String fileUrl) {
        return AliyunUtil.delete(fileUrl, blogProperties.getAliyun());
    }
}